package com.gujia.concurrency.example.atomic;

import com.gujia.concurrency.annoations.ThreadSafe;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;

@Slf4j
@ThreadSafe
public class AtomicExample4 {
    
    public static AtomicReference<Integer> count = new AtomicReference<Integer>(0);
    
    public static void main(String[] args) throws Exception {

        count.compareAndSet(0,2);// yes 2
        count.compareAndSet(0,1);//no 2
        count.compareAndSet(1,3);//no 2
        count.compareAndSet(2,4);//yes 4
        count.compareAndSet(3,5);//no 4

        System.out.println(count);
    }


}
